package com.ziDingYiValidator2;

import com.exception.ValidateException;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
public class UpperCtrl {

    @GetMapping(value = "/upper")
    @ResponseBody
    public String upper(@Valid Upper upper, BindingResult result){
        if (result.hasErrors()){
            throw new ValidateException(result.getFieldErrors());
        }
        return upper.getStr();
    }
}
